package com.baselibrary.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.ScrollView;

import com.baselibrary.utils.ScreenUtils;

/**
 * @author:hanke 2022/6/30
 * desc:
 */
public class MaxHeightScrollView extends ScrollView {

    private int maxHeight= ScreenUtils.dpToPx(200);

    public MaxHeightScrollView(Context context) {
        super(context);
    }

    public MaxHeightScrollView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initialize(context, attrs);
    }

    public MaxHeightScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initialize(context, attrs);
    }


    private void initialize(Context context, AttributeSet attrs) {
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (maxHeight > 0) {
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(maxHeight, MeasureSpec.AT_MOST);
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

}